<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">

	</style>
	<!-- 百度地图 -->
	<script type="text/javascript"
		src="https://api.map.baidu.com/api?v=2.0&ak=UQvKfiufvmQU7LhjOQvDwclGSrQS5pPJ"></script>
	<title>浏览器定位</title>
</head>

<body>
	<p>省份：<span id="province"></span></p>
	<p> 城市：<span id="city"></span></p>
</body>

</html>
<script src="../../public/cookieTools.js"></script>
<script type="text/javascript">
	// 百度地图API功能
	var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function (r) {
		if (this.getStatus() == BMAP_STATUS_SUCCESS) {
			console.log(r.point.lng + "__" + r.point.lat);
			getAddress(r.point.lng, r.point.lat);
		}
		else {
			alert('failed' + this.getStatus());
		}
	}, { enableHighAccuracy: true })

	function getAddress(lng, lat) {
		var myGeo = new BMap.Geocoder();
		// 根据坐标得到地址描述    
		myGeo.getLocation(new BMap.Point(lng, lat), function (result) {
			if (result) {
				var province = result.addressComponents.province;
				var city = result.addressComponents.city;
				var detail = result.address;
				console.log(province)
				console.log(city)
				document.getElementById("province").innerText = province;
				document.getElementById("city").innerText = city;
				saveCookie("province", province, 7)
				saveCookie("city", city, 7)
				saveCookie("detail", detail, 7)
			}
		});
	}
</script>